<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加客户</title>
		<link rel="stylesheet" type="text/css" href="${BASE_PATH}/static/lib/layui/css/layui.css" />
	</head>

	<body>
		<form class="layui-form" action="" style="margin: 10px 10px 0 10px;">
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="yhUserName" lay-verify="yhUserName" placeholder="" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">身份证号</label>
				<div class="layui-input-inline">
					<input id="idCard" type="text" name="yhUserIdcard" placeholder="" autocomplete="off" class="layui-input idCard" lay-verify="identity">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
				<label class="layui-form-label">出生日期</label>
					<div class="layui-input-inline">
						<input type="text" name="time" class="layui-input" id="test1" lay-verify="date" placeholder="yyyy-MM">
					</div>
				</div>
				<div class="layui-inline">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-block">
					<input type="radio" name="yhUserSex" value="0" title="男" checked="">
					<input type="radio" name="yhUserSex" value="1" title="女">
				</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">电话号码</label>
				<div class="layui-input-inline">
					<input type="text" name="yhUserPhone" placeholder="" autocomplete="off" class="layui-input" lay-verify="phone">
				</div>
				<label class="layui-form-label">业务负责人</label>
				<div class="layui-input-inline">
					<input type="text" data-id="${user.userId}" name="userId" value="${user.name}" disabled placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">家庭详细地址</label>
				<div class="layui-input-inline" style="width: 499px;">
					<input type="text" name="yhUserAdds" lay-verify="yhUserAdds" placeholder="" autocomplete="off" class="layui-input" lay-verify="required">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="demo1"><i class="layui-icon">&#x1005;</i>保存</button>
				</div>
			</div>
		</form>
	</body>
	<script src="${BASE_PATH}/static/lib/layui/layui.js"></script>
	<script>
		layui.use(['form', 'layedit', 'laydate', 'jquery', 'table'], function() {
			var form = layui.form,
				layer = layui.layer;
			var $ = layui.jquery;
			var table = layui.table;
			var laydate = layui.laydate;

			//出生日期
			laydate.render({
				elem: '#test1'
			});

			//自定义验证规则
			form.verify({
				yhUserName: function(value) {
					if(value.length < 1) {
						return '姓名不能为空';
					}
				},
				yhUserAdds: function(value) {
					if(value.length < 1) {
						return '家庭住址不能为空';
					}
				}
			});

			//监听提交
			form.on('submit(demo1)', function(data) {
				$.ajax({
					type: 'POST',
					url: '${BASE_PATH}/admin/user/ajax_user_add',
					data: data.field,
					success: function(res) {
						if(res.success == true) {
							alert(res.msg);
							parent.location.reload();
						} else {
							alert("添加失败，请稍后再试！");
							parent.location.reload();
						}
					}
				})
				return false;
			});
			
			//身份证失焦
			$("#idCard").on("blur",function(){
				var idCard = $("#idCard").val();
				$.ajax({
					type:'POST'
					,url:'${BASE_PATH}/admin/user/ajax_user_idCard'
					,data:{yhUserIdcard:idCard}
					,success:function(res){
						if(res.success == true){
							alert(res.msg)
							parent.location.reload();
						}
					}	
				})
			})

		});
	</script>

</html>